package models

import (
	"github.com/beego/beego/v2/client/orm"
	"time"
)

// Skill 技能
type Skill struct{
	Id int64
	Name string
	Desc string
	Level int8
	Grade int8
	CreateTime time.Time 		`orm:"auto_now_add;null"`
	UpdateTime time.Time 		`orm:"auto_now;null"`
	IsDelete bool 				`orm:"default(0)" json:"-"`
	//User *User `orm:"rel(fk)" json:"-" `
}

func (Skill) TableName() string {
	return "t_skill"
}

func NewSkill() *Skill {
	return &Skill{}
}


// Save 保存
func (skill *Skill) Save() (int64, error) {
	o := orm.NewOrm()
	return o.Insert(skill)
}

// Update 更新指定字段
func (skill *Skill) Update(cols ...string) (int64, error) {
	o := orm.NewOrm()
	return o.Update(skill, cols...)
}

// Delete 删除
func (skill *Skill) Delete() (int64, error) {
	o := orm.NewOrm()
	return o.Delete(skill)
}

// DelLogic 逻辑删除
func (skill *Skill) DelLogic() error {
	if skill.Id < 1 {
		return nil
	}
	o := orm.NewOrm()
	_, err := o.QueryTable(skill).Filter(IdColumnName, skill.Id).Update(orm.Params{
		"is_delete": 1,
	})
	return err
}

// GetById 根据id获取
func (skill *Skill) GetById() error {
	o := orm.NewOrm()
	return o.Read(skill)
}